<template>
  <div>
    <div>
        <input class="moblie" type="text" v-model="loginForm.username" placeholder="用户名"/>
        <p class="error-tip" v-show="!this.loginForm.username">用户名不能为空</p>
    </div>
    <div>
       <input class="password" type="password" v-model="loginForm.password" placeholder="密码"/>
       <p class="error-tip" v-show="!this.loginForm.password">密码不能为空</p>
    </div>
   
    <button @click="login" :disabled="!this.loginForm.username || !this.loginForm.password">登录</button>
    <div>
      <span>注册</span>
      <span>手机号登录</span>
    </div>
  </div>
</template>

<script>

import axios from 'axios'    
export default {
  data () {
    return {
      loginForm: {
        username: "",
        password: ""
      },
    };
  },
  methods:{
    login(){
        let _this = this; 
        axios.post('/api/login', _this.loginForm).then(res => {
          if(res.data.code == "1"){
            console.log(res.data.token);
            
              window.sessionStorage.setItem('token', this.$md5(res.data.token));
              window.sessionStorage.setItem('session', res.data.user_name);
              _this.$router.push('/home');
          }else{
              alert(res.data.msg)
          }
        }).catch(error =>{
              console.log("错误" + error);
        })
     
    }
  }
}
</script>

<style>

</style>